<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-name" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}"  data-rule="required" >
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Cover_img')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-cover_img" class="form-control" size="50" name="row[cover_img]" type="text" value="{$row.cover_img|htmlentities}" data-rule="required">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-cover_img" class="btn btn-danger faupload" data-input-id="c-cover_img" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-cover_img"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-cover_img" class="btn btn-primary fachoose" data-input-id="c-cover_img" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-cover_img"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-cover_img"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Rebate')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-rebate" class="form-control"  name="row[rebate]" type="number" value="{$row.rebate|htmlentities}">
                <div class="input-group-addon">折</div>
            </div>
            <p class="text-gray" style="margin-top: 5px;">温馨提示：请输入0.1~10之间的数字,值为空代表不设置折扣 </p>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Is_upgrade')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="radio">
                {foreach name="upgradeList" item="vo"}
                <label for="row[is_upgrade]-{$key}"><input id="row[is_upgrade]-{$key}" name="row[is_upgrade]" type="radio" value="{$key}" {in name="key" value="$row.is_upgrade"}checked{/in} /> {$vo}</label>
                {/foreach}
            </div>
        </div>
    </div>
        <div class="form-group class_is_upgrade">
            <label class="control-label col-xs-12 col-sm-2">{:__('Start_time')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-start_time" class="form-control datetimepicker"   name="row[start_time]" type="text" value="{$row.start_time}">
            </div>
        </div>
        <div class="form-group class_is_upgrade">
            <label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
            <div class="col-xs-12 col-sm-8">
                <input id="c-end_time" class="form-control datetimepicker"  name="row[end_time]" type="text" value="{$row.end_time}">
            </div>
        </div>

    <div class="form-group class_is_upgrade">
        <label class="control-label col-xs-12 col-sm-2">{:__('use_price')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-use_price" class="form-control" step="0.01" name="row[use_price]" type="number"  value="{$row.use_price}"/>
                <div class="input-group-addon">元</div>
            </div>
        </div>
    </div>
    <div class="form-group class_is_upgrade">
        <label class="control-label col-xs-12 col-sm-2">{:__('Day_num')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-day_num" class="form-control" name="row[day_num]" type="number"  value="{$row.day_num}"/>
                <div class="input-group-addon">天</div>
            </div>
            <p class="text-gray" style="margin-top: 5px;">温馨提示:满足会员条件时，往后推相应天数， -1代表永久有效 </p>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Rule')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-rule" class="form-control editor" rows="5" name="row[rule]" cols="50"  data-rule="required" >{$row.rule|htmlentities}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
        <div class="col-xs-12 col-sm-8">
            
            <div class="radio">
            {foreach name="statusList" item="vo"}
            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label>
            {/foreach}
            </div>

        </div>
    </div>

    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>
<script>
    // 获取单选框元素
    var radioOptions = document.getElementsByName("row[is_upgrade]");
    var class_is_upgrade = document.getElementsByClassName("class_is_upgrade")

    var is_upgrade = <?php echo $row['is_upgrade']; ?>

    if(is_upgrade == 2){
        for (var i = 0; i<class_is_upgrade.length;i++) {
            class_is_upgrade[i].style.display="none";
        };
    }

    // 监听单选框的选择变化
    for (var i = 0; i < radioOptions.length; i++) {
        radioOptions[i].addEventListener("change", function() {
            var selectedOption = this.value;
            console.log(selectedOption)
            var class_is_upgrade = document.getElementsByClassName("class_is_upgrade")
            // 根据选择结果显示或隐藏其他元素
            if (selectedOption == "1") {

                for (var i = 0; i<class_is_upgrade.length;i++) {
                    class_is_upgrade[i].style.display="block";
                };
            } else if (selectedOption === "2") {
                // document.getElementsByClassName("class_is_upgrade")[0].style.display = "none";
                for (var i = 0; i<class_is_upgrade.length;i++) {
                    class_is_upgrade[i].style.display="none";
                };
            }
        });
    }
</script>

